/*******************************************************************************
 * Course :					LOG210
 * Session :				winter 2012
 * Group :					02
 * Team :					3
 * Project :				Iteration 01
 * Students :				Nicolas Lefebvre			LEFN06078909
 * 							Jean-Philippe Chapdelaine	CHAJ13099001
 * 							Dalin Son					SOND05099000
 * 							Philippe Nichols			NICP29109007
 * Teacher :				François Caron
 * 							Jean-Philippe Martin
 * Created :				Jan 25, 2012
 * Date dern. modif. :		see revesion history
 * 
 * =============================================================
 *	Revision history
 * =============================================================
 *	Jan 25, 2012	Class created
*******************************************************************************/
package model;

import java.util.*;

public class Commande 
{
	private boolean isOpen;
	private Restaurant restaurant;
	private Client client;
	private Date date;
	private Coordonee coordonee;
	private ArrayList<LignePlat> selection;
	private int noConfirmation;
	
	public Restaurant getRestaurant()
	{
		return restaurant;
	}
	public void setRestaurant(Restaurant restaurant)
	{
		this.restaurant = restaurant;
	}
	public int getNoConfirmation()
	{
		return noConfirmation;
	}
	public boolean isOpen()
	{
		return isOpen;
	}
	public Date getDate()
	{
		return date;
	}
	public Coordonee getCoordonee()
	{
		return coordonee;
	}
	public void setCoordonee(Coordonee coordonee)
	{
		this.coordonee = coordonee;
	}
	
	public Commande()
	{
		this.isOpen = true;
		this.selection = new ArrayList<LignePlat>();
		this.noConfirmation = -1;
	}
	
	public Commande(Client client)
	{
		this();
		this.client = client;
		this.coordonee = client.getCoordonee();
	}
	
	/**
	 * Ferme la commande si elle contient au moins une selection
	 * @return true si la commande a bien ete ferme
	 */
	public boolean fermerCommande()
	{
		if (!this.selection.isEmpty())
		{
			this.isOpen = false;
		}
		return !this.isOpen;
	}
	
	/**
	 * Genere le numero de confirmation
	 */
	private void genererNoConfirmation()
	{
		//TODO: FAIRE DE QUOI QUI GENERE UN NO DE CONFIRMATION
		this.noConfirmation = 1;
	}
	
	/**
	 * Confirme la commande
	 * @param date de la livraison
	 * @return true si la commande a bien ete confirmer
	 */
	public boolean confirmerCommande(Date date)
	{
		boolean commandeValide = this.client != null && 
								 this.restaurant != null && 
								 this.coordonee != null && 
								 !this.selection.isEmpty() && 
								 !this.isOpen;
		
		this.date = date;
		
		if(commandeValide)
		{
			this.genererNoConfirmation();
		}
		return commandeValide && this.noConfirmation != -1;
	}
}